package com.liao.r2dbc.dao.impl;

import com.liao.r2dbc.dao.CustomUserDao;
import com.liao.r2dbc.pojo.TbUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.r2dbc.core.DatabaseClient;
import reactor.core.publisher.Flux;

public class CustomUserDaoImpl implements CustomUserDao {

    @Autowired
    private DatabaseClient databaseClient;

    @Override
    public Flux<TbUser> myFindAll() {
        return databaseClient.sql("select * from user where id > :0")
                .bind(0,1)
                .map(row -> {
                    TbUser tbUser = new TbUser();
                    tbUser.setId(row.get("id",Integer.class));
                    tbUser.setUsername(row.get("username",String.class));
                    tbUser.setPassword(row.get("password",String.class));
                    return tbUser;
                }).all();
    }
}
